package com.hnx.admin.system.service.impl;

import com.hnx.admin.api.log.LogHandler;
import com.hnx.admin.enums.logs.LogType;
import com.hnx.admin.system.domain.param.log.loginInfo.form.LoginInforForm;
import com.hnx.admin.system.domain.param.user.form.UserForm;
import com.hnx.admin.system.mapper.log.LoginInforMapper;
import com.hnx.admin.system.mapper.user.UserMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/*
项目名称： core
创 建 人: 倔强的头发
创建日期： 2025/6/9   9:26:29 
描   述：
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class LoginLogHandler implements LogHandler<LoginInforForm> {
    private final LoginInforMapper loginInforMapper;
    private final UserMapper  userMapper;
    @Override
    public LogType getLogType() {
        return LogType.LOGIN;
    }
    @Override
    @Async("loginExecutor")
    public void asyncSaveLog(LoginInforForm loginInforForm) {
        loginInforMapper.insertLogininfor(loginInforForm);
        if(loginInforForm.getStatus() == 0) {
            UserForm  userForm = new UserForm();
            userForm.setUserId(loginInforForm.getUserId());
            userForm.setLoginIp(loginInforForm.getIp());
            userMapper.updateEmp(userForm);
        }
    }
}
